class Solution:
    def romanToInt(self, s: str) -> int:
        dict = {'M':1000,'D':500,'C':100,'L':50,'X':10,'V':5,'I':1}
        sum = 0
        for i in range(len(s)-1):
            if dict[s[i]] >= dict[s[i+1]]:
                sum = sum + dict[s[i]]
            else:
                sum = sum - dict[s[i]]
        sum = sum + dict[s[len(s)-1]]
        return sum
